<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 准备好一个容器 -->
    <div id="text"></div>
    <!-- react 核心库 -->
    <script type="text/javascript" src="../js/react.development.js"></script>
    <!-- 引入react-dom 支持react dom 操作 -->
    <script type="text/javascript" src="../js/react-dom.development.js"></script>

    <!-- 蒋jsx装换为js  -->
    <script type="text/javascript" src="../js/babel.min.js"></script>
    <script type="text/babel">
        //创建组件
        class Count extends React.Component {
            //构造器
            constructor(props) {
                console.log('Count-constructor')
                super(props)
                //初始化状态
                this.state = { count: 0 }
            }
            //加1回调函数
            add = () => {
                //获取原来的状态
                const { count } = this.state
                //更新状态
                this.setState({ count: count + 1 })
            }
             //卸载组件
             death = () => {
                //清楚定时器
                clearInterval(this.timer)
                ReactDOM.unmountComponentAtNode(document.getElementById('text'))
            }
            //组件将要挂载的钩子
            componentWillMount() {
                console.log('Count--componentWillMount')
            }
            //组件完成挂载页面之后调用
            componentDidMount() { 
                console.log('Count---componentDidMount')
            }
            //组件将要卸载的钩子
            componentWillUnmount(){
                console.log('Count---componentWillUnmount')
            }
            //控制组件更新的阀门
            shouldComponentUpdate(){
                console.log('Count---shouldComponentUpdate')
                return true
            }
            //组件将要更新的钩子
            componentWillUpdate(){
                console.log('Count---componentWillUpdate')
            }
            //组件更新完毕的钩子
            componentDidUpdate(){
                console.log('Count--- componentDidUpdate')
            }
            render() {
                console.log('Count---render')
                const { count } = this.state
                return (
                    <div>
                        <h2>当前求和为:{count}</h2>
                        <button onClick={this.add}>点我+1</button>
                        <button onClick={this.death}>卸载</button>
                    </div>
                )
            }
        }
        ReactDOM.render(<Count />, document.getElementById('text'))
    </script>
</body>

</html>